<!-- NewTrainOrderList.html -->
<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
	<title></title>
	<link rel="stylesheet" type="text/css" href="../../css/mui.min.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/html-base.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/public-train.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/train.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/base.css"/>
    <style type="text/css">
    	.ordercontainer {
		    padding-top: 0.4rem;
		}
    </style>
</head>
	
<body>
	<div class="ordercontainer">
		<div class="listwrapper orderwrapper">
			<ul id="order_list" class="listbox">
				<!-- <li>
					<a href="javascript:;">
						<div class="u-img"><img src="../../image/default-pic01.png"></div>
						<div class="u-txt">
							<h3>货运代理师资培训班</h3>
							<p>本培训将线上和线下，理论知识和专业技能有机结合在一起，并平结合在一起，并平</p>
							<div><p class="marktxt">2018-12-15</p> <span class="pricetxt">￥12800.00</span></div>
						</div>
					</a>
					<div class="order-statusbox">
						<span class="status-txt">线下支付</span>
						<a class="status-btn waitingsk">等待审核</a>
					</div>
				</li>
				<li>
					<a href="javascript:;">
						<div class="u-img"><img src="../../image/default-pic01.png"></div>
						<div class="u-txt">
							<h3>货运代理师资培训班</h3>
							<p>本培训将线上和线下，理论知识和专业技能有机结合在一起，并平结合在一起，并平</p>
							<div><p class="marktxt">2018-12-15</p> <span class="pricetxt">￥12800.00</span></div>
						</div>
					</a>
					<div class="order-statusbox">
						<span class="status-txt success">审核成功</span>
						<a class="status-btn successgoing" href="train-det-px2.html">进入班级</a>
					</div>
				</li>
				<li>
					<a href="javascript:;">
						<div class="u-img"><img src="../../image/default-pic01.png"></div>
						<div class="u-txt">
							<h3>挡不住的跨境电商时代</h3>
							<p>本培训将线上和线下，理论知识和专业技能有机结合在一起，并平结合在一起，并平</p>
							<div><p class="marktxt">2018-12-15</p> <span class="pricetxt">￥12800.00</span></div>
						</div>
					</a>
					<div class="order-statusbox">
						<span class="status-txt">银行卡支付</span>
						<a class="status-btn waitingaccount">等待到账</a>
					</div>
				</li>
				<li>
					<a href="javascript:;">
						<div class="u-img"><img src="../../image/default-pic01.png"></div>
						<div class="u-txt">
							<h3>挡不住的跨境电商时代</h3>
							<p>本培训将线上和线下，理论知识和专业技能有机结合在一起，并平结合在一起，并平</p>
							<div><p class="marktxt">2018-12-15</p> <span class="pricetxt">￥12800.00</span></div>
						</div>
					</a>
					<div class="order-statusbox">
						<span class="status-txt">款项已到账</span>
						<a class="status-btn" href="train-det-kc2.html">进入学习</a>
					</div>
				</li> -->
			</ul>
			<div class="noSign" hidden="hidden" id="noData">
				<img src="../../image/default-pic03.png" width="60%">
				<p class="font16 top_15 base_dark_grey" >
					暂无任何订单
				</p>
			</div>
			<div class="loadFailure" hidden="hidden" id="noNet">
				<img src="../../image/icon_img01.png" width="60%">
				<p class="" >
					数据加载失败
				</p>
				<p>
					请检查您的网络
				</p>
				<button type="button" class="mui-btn mui-btn-outlined" onclick="refreshData()">
					重新加载
				</button>
			</div>
		</div>
	</div>
</body>
<script type="text/javascript" src="../../script/newresize.js"></script>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/jquery.min.js"></script>
<script type="text/javascript" src="../../script/mui.min.js"></script>
<script type="text/javascript" src="../../script/MD5.js"></script>
<script type="text/javascript" src="../../script/requestTool.js"></script>
<script type="text/javascript" src="../../script/timeStampTool.js"></script>
<script type="text/javascript" src="../../script/utils/payUtils.js"></script>
<script type="text/javascript">
	var page = 1;
	var rows = 10;
	var dropRefreshCount = 0;
	var orderArr = new Array();
	apiready = function(){
		setRefreshHeader();
		setPullUpRefresh();
		loadData();
		api.addEventListener({
			name: 'aliPayResult'
		}, function(ret, err) {
			if(ret.value.code==="4000") {
				api.closeWin({
					name: 'signup-kc'
				});
				api.toast({
					msg: '支付成功'
				});
				refreshData();//刷新课程状态
			}
		});
	}
	//下拉刷新
	function setRefreshHeader() {
		api.setRefreshHeaderInfo({
			visible : true,
			bgColor : '#ccc',
			textColor : '#fff',
			textDown : '下拉刷新...',
			textUp : '松开刷新...',
			showTime : true
		}, function(ret, err) {
			refreshData();
		});
	}
	// 上拉加载
	function setPullUpRefresh() {
		api.addEventListener({
			name : 'scrolltobottom'
		}, function(ret, err) {
			if (dropRefreshCount >= rows) {
				dropRefreshCount = 0;
				page++;
				loadData();
			}
		});
	}
	function refreshData(){
		page = 1;
		loadData();
	}
	function loadData(){
		if (page == 1) {
			api.showProgress({
			    style: 'default',
			    animationType: 'fade',
			    title: '数据加载中...',
			    text: '',
			    modal: false
			});
		}
		var params = {
			page : page, 
			rows : rows,
			uid : $api.getStorage('cfnetppuid')
			// uid : '15107'
		};
		cfnetppPOST(url_train_getOrderList, params, true, function(data, status){
			api.refreshHeaderLoadDone();
			api.hideProgress();
			if (status == "success") {
				if (data.code == 200) {
					if (page == 1) {
						orderArr = [];
						$('#order_list').html('');
					}
					var courses = data.data.data;
					if (courses != undefined && courses != null && courses.constructor == Array && courses.length > 0) {
						$('#noData').hide();
						$('#noNet').hide();
						dropRefreshCount = courses.length;
						setupCourseHtml(courses);
					}else{
						$('#order_list').html('');
						$('#noData').show();
						$('#noNet').hide();
					}
				}else{
					if (page == 1) {
						$('#order_list').html('');
						$('#noData').show();
						$('#noNet').hide();
					}
				}
			}else{
				if (page == 1) {
					$('#order_list').html('');
					$('#noData').hide();
					$('#noNet').show();
				}
			}
		});
	}
	function setupCourseHtml(arr){
		var oldCount = orderArr.length;
		orderArr = orderArr.concat(arr);
		var newCount = orderArr.length;
		for (var i = oldCount; i < newCount; i++) {
			var orderData = orderArr[i];
			$('#order_list').append(courseCellHtml(i, orderData));
		}
		setupCellClick();
	}
	function setupCellClick(){
		$('.order-cell').unbind('click');
		$('.order-cell').click(function(){
			// return;//暂不跳转
			var index = $(this).attr('index');
			var orderData = orderArr[parseInt(index)];
			console.log(JSON.stringify(orderData));
			orderData["id"]=orderData.link_id;

			var category_id = orderData.category_id;
			var status = orderData.status;
			if (status == 3 || status == 7) {
				orderData["buyStatus"] = 1;
			}

			if (category_id == 111) {
				api.openWin({useWKWebView:true,
				    name: 'train-det-px',
				    url: 'train-det-px.html',
				    pageParam: orderData
				});
			}else{
				api.openWin({useWKWebView:true,
				    name: 'train-det-kc',
				    url: 'train-det-kc.html',
				    pageParam: orderData
				});
			}
		});
		$('.jump-btn').unbind('click');
		$('.jump-btn').click(function(event){
			event.stopPropagation();
			var index = $(this).attr('index');
			var orderData = orderArr[parseInt(index)];
			var category_id = orderData.category_id;
			orderData["buyStatus"] = 1;
			orderData["id"]=orderData.link_id;
			console.log(JSON.stringify(orderData));
			if(orderData.status===0){
				getOrderInfo(orderData.link_id,category_id);
				return;
			}
			if (category_id === 111) {
				api.openWin({useWKWebView:true,
				    name: 'train-det-px',
				    url: 'train-det-px.html',
				    pageParam: orderData
				});
			}else{
				api.openWin({useWKWebView:true,
				    name: 'train-det-kc',
				    url: 'train-det-kc.html',
				    pageParam: orderData
				});
			}
		});
	}
	function courseCellHtml(index, data){
		var category_id = data.category_id;
		var status = data.status;
		// var pay_type = data.pay_type;
		var statusBtnClass = '';
		var statusTitle = '';
		switch(status){
			case 0://待支付
			statusTitle = '待支付';
			statusBtnClass = 'waitingaccount';
			break;
			case 1://等待到账
			statusTitle = '待到账';
			statusBtnClass = 'waitingaccount';
			break;
			case 2://等待审核
			statusTitle = '待审核';
			statusBtnClass = 'waitingsk';
			break;
			case 3://支付完成
			statusTitle = '支付完成';
			statusBtnClass = 'successgoing';
			break;
			case 4://订单失效
			statusTitle = '订单失效';
			statusBtnClass = 'waitingaccount';
			break;
			case 5://订单关闭
			statusTitle = '订单关闭';
			statusBtnClass = 'waitingaccount';
			break;
			case 6://支付失败
			statusTitle = '支付失败';
			statusBtnClass = 'waitingaccount';
			break;
			case 7://审核通过
			statusBtnClass = 'successgoing';
			statusTitle = '审核通过';
			break;
		}
		var canJumpBtnClass = 'jump-btn';
		if (category_id == 111) {//班级
			if (status == 3 || status == 7) {
				statusTitle = '进入班级';
				canJumpBtnClass = "jump-btn";
			}
		}else{//课程
			if (status == 3 || status == 7) {
				statusTitle = '进入学习';
				statusBtnClass = '';
				canJumpBtnClass = "jump-btn";
			}
		}
		return '<li index="'+index+'" class="order-cell">'+
					'<a href="javascript:;">'+
						'<div class="u-img"><img onerror="this.src=\'../../image/icon_changfengjun.png\'"  src="'+data.imgge+'"></div>'+
						'<div class="u-txt">'+
							'<h3>'+data.product_name+'</h3>'+
							'<p>'+data.brief+'</p>'+
							'<div><p class="marktxt">'+timeStringWithTimeStamp(data.createtime)+'</p> <span class="pricetxt">￥'+data.product_price+'</span></div>'+
						'</div>'+
					'</a>'+
					'<div class="order-statusbox">'+
						'<a index="'+index+'" class="status-btn '+statusBtnClass+' '+canJumpBtnClass+'">'+statusTitle+'</a>'+
					'</div>'+
				'</li>';
	}
	function getOrderInfo(link_id,category_id) {
		var params = {
			link_id: link_id,
			category_id: category_id
		};

		cfnetppPOST(url_getOrderInfo, params, false, function (data, status) {
			if (status == 'success') {
				if (data.code == 200) {
					pay(PAY_TYPE.PAY_ALI,data.data);
				}
			}
		});
	}
</script>
</html>
